<template>
	<view class="page page-fill">
		  <form @submit="submitNicknameForm" class="form">
			  <view class="input-wrap">
				  <input
				   type="text"
				  :value="oldnickname" 
				   placeholder="请输入呢称" 
				   class="input"
				   name="nickname"
				   maxlength="10"/>
			  </view>
		 
		       <button class="btn" form-type="submit" type="primary">提交</button>
		  </form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
		      oldnickname:""
			}
		},
		onLoad(params){
		var nickname = params.nickname;
		    this.oldnickname = nickname
			  
		},
		methods: {
		  submitNicknameForm(e){
		    var userInfo =  uni.getStorageSync('globalInfo');
			var newNickname = e.detail.value.nickname;
			   uni.showLoading({
			   	mask:true
			   });
			     uni.request({
			   	  url:this.serverUrl + "/user/modifyUserinfo?qq=3316368400",
				  header:{
				  	"headerUserId":userInfo.id,
				  	"headerUserToken":userInfo.userUniqueToken
				  },
				  data:{
					 "userId":userInfo.id,
					 "nickname":newNickname,
				  },
                  method:"POST",
				  success:(res)=>{
					   var data = res.data;
					       console.log(data);
						   
					   if(data.status === 200){
						  uni.setStorageSync('globalInfo',data.data);
						  uni.navigateBack({
						  	delta:1
						  })
					   }else{
						   uni.showToast({
							  title:"修改失败"
						   });
					   }
				  },
				  complete:()=>{
				    uni.hideLoading();
				  }
			   })
		  }	
		}
	}
</script>

<style>
 .form{
	 padding: 0 40upx;
	 vmargin-top: 40upx;
 }
 .input-wrap{
	 background-color: #fff;
	 height: 90upx;
 }
.input{
	font-size:20px;
	color: #515050;
	height: 80upx;
	padding: 0 40upx;
	font-weight: 540;
}
.btn{
	margin-top: 40upx;
	width: 95%;
}

</style>
